﻿@model IEnumerable<Article>
@{
    Ajax.Dna().Widget()
        .UserPreferences(@<text>
    <div>
        @Html.Global("publishing", "SelectCategory")</div>
    @(
 Ajax.Dna().TreeView(item.GenerateFieldID("TreeView"))
             .HtmlAttributes(new { style = "height:200px;border:1px solid #cccccc;overflow:auto;padding-top:10px;" })
             .Options(opts =>
             {
                 opts.OnNodeSelected = "$(\"#" + item.GenerateFieldID("CategoryID") + "\").val($(node).attr(\"key\"));";
                 opts.SinglePathExpand = true;
             })
             .ExpandedLevel(1)
             .SelectNode("key", item.UserPreferences["CategoryID"].ToString())
             .Bind(((HierarchicalNodeProviderBase)ViewBag.Provider).RootNode, node =>
             {
                 node.NavigateUrl = "javascript:void(0);";
                 node.ImageUrl = Url.Content("~/content/images/icon_cat_16.gif");
                 return true;
             }, true).GetHtml()
        )
    <input type="hidden" value="@item.GetInt("CategoryID")" id="@item.GenerateFieldID("CategoryID")" name="@item.GenerateFieldID("CategoryID")" />
    <div>
        <div>
            @Html.Global("publishing", "DisplayTextLen")</div>
        <div>
            @Ajax.Dna().Number(item.GenerateFieldID("TextLen"), item.GetInt("TextLen")).GetHtml()
        </div>
        <div>
            ( @Html.Global("publishing", "DisplayTextLenTip") )</div>
    </div>
    </text>)
.Preview(item =>
{
    Ajax.Dna().Menu(item.GenerateFieldID("articleMenu"))
                        .ChangeType(MenuTypes.Vertical)
                        .Items(items =>
                        {
                            items.Add("Post1 title", "javascript:void(0);");
                            items.Add("Post2 title", "javascript:void(0);");
                            items.Add("Post3 title", "javascript:void(0);");
                            items.Add("Post4 title", "javascript:void(0);");
                            items.Add("Post5 title", "javascript:void(0);");
                            items.Add("Post6 title", "javascript:void(0);");
                        })
                        .Render();
})
        .Content(item =>
        {
            if (Model != null)
            {
                Ajax.Dna().Menu(item.GenerateFieldID("articleMenu"))
                    .ChangeType(MenuTypes.Vertical)
                    .Items(items =>
                    {
                        foreach (var art in Model)
                        {
                            var article = new ArticleWrapper(art);
                            if (!article.IsVisible(Context))
                            {
                                continue;
                            }
                            var content = article.GetGlobalizationContent();
                            items.Add(((item.GetInt("TextLen")) > -1 ? Html.Cut(content.Title, item.GetInt("TextLen")) : content.Title), article.PermaLink);
                        }
                    })
                    .Render();
            }
        })
        .Render();
}
